package com.gprinter.utils;

import android.bluetooth.BluetoothAdapter;

/**
 * FileName: BluetoothUtils
 * Author: Greetty
 * Time: 2018/12/8 15:47
 * Desc: TODO
 */
public class BluetoothUtils {

    /**
     * 获取蓝牙连接状态
     *
     * @return boolean
     */
    public static boolean getBluetoothState() throws Exception {

        BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        // If the adapter is null, then Bluetooth is not supported
        if (mBluetoothAdapter == null) {
//            throw new Exception("Bluetooth is not supported by the device");
            throw new Exception("此设备不支持蓝牙功能");
        } else {
            if (!mBluetoothAdapter.isEnabled()) {
//                throw new Exception("Bluetooth is disabled");
                throw new Exception("设备蓝牙未开启，请打开蓝牙并连接打印机.");
            }
        }
        return true;
    }

}
